import request from '/@/utils/request';
import request_out from '/@/utils/request_outside';
import { getApiUrl } from '/@/api/linxyun/linxyunapi';
import { AxiosRequestHeaders } from 'axios';
interface IResp {
	code: string;
	success: boolean;
	msg: string;
	Records?: any;
	TotalSize?: string;
	RowCnt?: string;
	data?: any;
}
export function httpReqeustApi() {
	return {
		Post: (uriName: string, params?: object, data?: object, header?: AxiosRequestHeaders): Promise<IResp> => {
			let url = getApiUrl(uriName);
			return request<IResp>({
				url: url,
				method: 'post',
				data: data,
				params: params,
				headers: header ?? {},
			});
		},
		Get: (uriName: string, params: object): Promise<IResp> => {
			let url = getApiUrl(uriName);
			return request<IResp>({
				url: url,
				method: 'get',
				params: params,
			});
		},
		SyncPost: async (uriName: string, params: object = {}, data: object = {}, headers: AxiosRequestHeaders = {}): Promise<IResp> => {
			let url = getApiUrl(uriName);
			return await request({
				url: url,
				method: 'post',
				data: data,
				params: params,
				headers,
			});
		},
		SyncGet: async (uriName: string, params: object): Promise<IResp> => {
			let url = getApiUrl(uriName);
			return await request({
				url: url,
				method: 'get',
				params: params,
			});
		},
		SyncPostOutside: async (url: string, params: object, data: object, onUploadProgress = () => {}) => {
			return await request_out({
				url: url,
				method: 'post',
				data: data,
				params: params,
				onUploadProgress,
			});
		},
		SyncGetOutside: async (url: string, params: object) => {
			return await request_out({
				url: url,
				method: 'get',
				params: params,
			});
		},
	};
}
